package com.lecture.junit.tdd.example.util;

import java.util.Arrays;
import java.util.Date;

public class DateUtils {

    public static Date maxDate(Date... dates){
        if(dates.length == 1){
            return dates[0];
        }else if(dates.length >= 2){
            Date secondMax = maxDate(Arrays.copyOfRange(dates, 1, dates.length));
            if(dates[0] == null)
                return secondMax;
            if(secondMax == null){
                return dates[0];
            }
            return dates[0].after(secondMax)
                    ? dates[0]
                    : secondMax;
        } else {
            throw new RuntimeException("Something went wrong");
        }
    }

}
